//
//  TDVisitorViewController.swift
//  微博
//
//  Created by tong dan on 16/3/1.
//  Copyright © 2016年 tong dan. All rights reserved.
//

import UIKit

class TDVisitorViewController: UITableViewController {

  //用户是否登录开关
    var userLogin: Bool = TDUserAccountViewModel.shareViewModel.isLogon
   
    var visitorView: TDVisitorView?
    
    override func loadView() {
        //用户已经登录
        if userLogin{
        
        super.loadView()
            print("%@",[superclass])
        }else{
            
        //没有登录
            setupVisitorView()
        
        }
    }
    //没有登录设置访客视图
    private func setupVisitorView(){
    
    let v = TDVisitorView()
    visitorView = v
    view = v
    
    //设置左边的item
    navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "register")
    //设置右边的item
    navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "login")
        
    // 给访客视图里面的两个按钮点击事件
    v.registerButton.addTarget(self, action: "register", forControlEvents: UIControlEvents.TouchUpInside)
    v.loginButton.addTarget(self, action: "login", forControlEvents: UIControlEvents.TouchUpInside)

    }
    @objc private func register(){
    
    print("我要注册")
    
    }
    
    @objc private func login(){
        
        //登录后弹出一个webView
        presentViewController(TDNavigationViewController(rootViewController:TDOAuthViewController()), animated: true, completion: nil)
    
    }
    
}
